from diffusers import StableDiffusionPipeline
import torch

# 从预训练模型中加载Stable Diffusion管道
pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16
).to("cuda")

# 定义要生成图像的提示词
prompt = "A beautiful landscape with mountains and a lake"

# 生成图像
image = pipe(prompt).images[0]

# 保存图像
image.save("beautiful_landscape.png")